using Godot;
using System;

public partial class BigMap : Node2D
{
  public static bool IsUIActive = false;
  Sprite2D _bigMap;

  MarginContainer _cityInfoRoot;

  Button _closeButton;

  public override void _Ready()
  {
    _cityInfoRoot = GetNode<MarginContainer>("CanvasLayer/CityInfoRoot");
    _closeButton = GetNode<Button>("CanvasLayer/CityInfoRoot/CityInfoBackGroundTextureRect/MarginContainer/VBoxContainer/MarginContainer/HBoxContainer/CloseCityInfoButton");
    _closeButton.Pressed += _closeButtonOnClick;

    _bigMap = GetNode<Sprite2D>("BigMap");
    var children = _bigMap.GetChildren();

    foreach (var item in children)
    {
      GD.Print("city: " + item.Name);
      ((City)item).OnClick += _onClickHandler;
    }
  }

  private void _closeButtonOnClick()
  {
    _cityInfoRoot.Hide();
    IsUIActive = false;
  }

  public void _onClickHandler(City city)
  {
    _cityInfoRoot.Show();
    IsUIActive = true;
  }
}
